#include <iostream>
using namespace std;
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <netinet/in.h>
#include <cstring>
#include <arpa/inet.h>
int main()
{
    int sockfd = socket(AF_INET,SOCK_DGRAM,0);
    if(sockfd == -1)
    {
        perror("socket error:");
        exit(-1);
    }

    struct sockaddr_in serverAddr;
    memset(&serverAddr,0,sizeof(serverAddr));
    serverAddr.sin_family = AF_INET;
    serverAddr.sin_port = htons(8081);
    const char *ip = "127.0.0.1";
    inet_pton(AF_INET,ip,&(serverAddr.sin_addr.s_addr));

    char buffer[128] = "hello world.";
    int writeBytes = sendto(sockfd,buffer,sizeof(buffer),0,reinterpret_cast<const sockaddr*>(&serverAddr),sizeof(buffer));
    cout<<"writeBytes:"<<writeBytes<<endl;

    return 0;
}